package com.fairytask.ui
{
	import com.fairytask.data.BaseData;
	import com.fairytask.data.Record;
	import com.fairytask.data.RecordObject;
	import com.fairytask.engine.components.Scroll.ScrollPanel;
	import com.fairytask.engine.components.autoPullUpList.AutoPullUpList;
	import com.fairytask.engine.components.autoPullUpList.AutoPullUpListItem;
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.event.AutoPullUpListEvent;
	import com.fairytask.engine.components.tab.TabBar;
	import com.fairytask.engine.components.tab.TabEvent;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.engine.components.text.Text;
	import com.fairytask.engine.define.Filter;
	import com.fairytask.engine.define.RecordDefine;
	import com.fairytask.resource.StaticIni;
	import com.fairytask.ui.base.FrameUI;
	import com.fairytask.ui.item.TaskAwardItem;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.geom.Rectangle;
	
	/**
	 * 任务系统
	 * @author yangj
	 **/
	
	
	public class TaskUI extends FrameUI
	{
		//单例的自身
		private static var _self	:TaskUI;
		
		//显示
		private var _currentTask					:AutoPullUpList;
		private var _canTask						:AutoPullUpList;
		
		//任务面板总的背景显示
		public var bg_mc				:MovieClip;     			//整个任务的背景
		public var bg_mcL				:MovieClip;					//左边框的背景   	任务的下拉框
		public var bg_mcRU				:MovieClip;					//右上边框的背景   	任务详细（任务名，任务描述，任务超链接，任务奖励）
		public var bg_mcRD				:MovieClip;					//右下框的背景		放弃任务
		public var tabBar				:TabBar;					//已领取和可领取的tabBar
		
		// 完成任务按钮和放弃任务按钮
		public var giveUpButton		:Button;					//放弃任务按钮
		public var finishButton		:Button;					//完成任务按钮
		
		//任务描述信息容器定义
		public var infoSp				:Sprite	= new Sprite();  	//任务描述总容器
		private var _infoScrollPanel	:ScrollPanel; 				//信息描述容器滚动面板 
		public var nameSp				:Sprite	= new Sprite();		//任务名字层
		public var introduceSp			:Sprite	= new Sprite();		//任务描述容器层
		public var hyperlinkSp			:Sprite = new Sprite();		//超链接层
		public var awardSp				:Sprite = new Sprite();		//任务奖励层
		public var awardTextContainer	:Sprite = new Sprite();		//奖励文字显示容器
		public var awardItemContainer	:Sprite = new Sprite();		//奖励物品显示容器
		
		//任务名字层的显示
		public var nameBg				:MovieClip;					//任务名字的显示背景					
		public var nameTitleLab		:Label;						//任务名字
		public var nameText			:Text;						//具体任务名字
		
		//任务描述容器层显示
		public var introduceBg			:MovieClip;					//任务描述的显示背景	
		public var introduceTitleLab	:Label;						//任务描述
		public var introduceText		:Text;						//任务描述

		//超链接层显示
		public var hyperlinkBg			:MovieClip;					//超链接层的显示背景
		public var hyperlinkTitleLab	:Label;						//任务链接
		public var hyperlinkText		:Text;						//任务链接内容
		
		//任务奖励层
		public var awardBg							:MovieClip;		//任务奖励层的显示背景
		public var awardTitleLab					:Label;			//任务奖励
		public var expLab							:Label			//经验
		public var expInputLab						:Label			//经验 值
		public var silverLab						:Label			//银子
		public var silverInputLab					:Label			//银子 值
		public var bindSilverLab					:Label;			//灵气
		public var bindSilverInputLab				:Label;			//灵气 值
		public var goldLab							:Label;			//仙玉
		public var goldInputLab					:Label;			//仙玉值
		
		private var _currentTab					:int=0;
		//当前选择的任务
		private var _currentTaskId					:int	=	-1;
		
		//数据
		public static const DAILY_TASK			:int 	= 8;		//环任务
		private var _isDaily						:Boolean	=	false;
		private var _curRootItem					:AutoPullUpListItem;
		private var _canRootItem					:AutoPullUpListItem;
		
		private var _dataProcess:BaseData = new BaseData();//任务进度对象数据
		
		//绑定记录
		private var _bindAccArr					:Array	=	[]; //已接绑定
		
		//数据绑定
		private var killCount			:int;			//打怪几只?
		private var _step				:int	=	1;			//显示第几步
		private var _unbindArray		:Array = [];			//	解绑的数据
		
		private var _taskNumArray:Array=[];   //存放任务进度的数据
		
		private var _evt:AutoPullUpListEvent;
		//获得最佳的单例的对象
		
		public static function getInstance():TaskUI
		{
			if(_self == null)
			{
				_self = new TaskUI();
				//_self.dragEnable	=	true;
			}
			return _self;
		}
		
		public function TaskUI(popUI:Boolean = true)
		{
			super(popUI);			
		}
		
		//重写ui的显示
		override public function initGUI():void
		{
			//定义所有的显示格式
			nameText.setFilter();
			introduceText.setFilter();
			hyperlinkText.setFilter();
			expInputLab.labelFilter	=	silverInputLab.labelFilter	=	bindSilverInputLab.labelFilter	=	Filter.COMMON_TEXT_FILTER;
			
			
			//设置任务位置消息框
			introduceSp.y	=	58;
			hyperlinkSp.y	=	170;
			awardSp.y		=	228;
			
			//给内容显示框添加容器
			infoSp.addChild(nameSp);
			infoSp.addChild(introduceSp);
			infoSp.addChild(hyperlinkSp);
			awardSp.addChild(awardTextContainer);
			awardSp.addChild(awardItemContainer);
			infoSp.addChild(awardSp);
			
		
			_infoScrollPanel = new ScrollPanel(new Rectangle(0,0,275,382),infoSp);
			_infoScrollPanel.x = 220;
			_infoScrollPanel.y = 52;
			
			windowBG.addChild(_infoScrollPanel);
			
			_currentTask = new AutoPullUpList(178,305,"CustSkin_05","CustSkin_036","bgFrame_13","bgFrame_13",true,false);
			_currentTask.x=18;
			_currentTask.y=48;
			windowBG.addChild(_currentTask);
			
			_canTask = new AutoPullUpList(178,305,"CustSkin_05","CustSkin_036","bgFrame_13","bgFrame_13",true,false);
			_canTask.x=18;
			_canTask.y=48;
			windowBG.addChild(_canTask);
			_canTask.visible	=	false;
			
			
			initTree();//添加树根
			initEvent();
			bindData();//事件绑定
		}
		
		/**
		 * 添加树根
		 */
		private function initTree():void
		{
			var tmpTaskCatagory	:String	=	StaticIni.getIniVar("TaskUIList","Value");
			var tmpTaskArr : Array = tmpTaskCatagory.split(",");
			var tpStr:String;
			while(tmpTaskArr.length>0)
			{
				tpStr = tmpTaskArr.shift();
				//已接的树根
				_currentTask.addItem(StaticIni.getSwfLangStr(tpStr),tpStr);
				//可接的树根
				_canTask.addItem(StaticIni.getSwfLangStr(tpStr),tpStr);
			}
		}
		
		
		/**
		 *初始化事件
		 */
		private function initEvent():void
		{
			//点击不同的根项
			_currentTask.addEventListener(AutoPullUpListEvent.AUTO_CLICK_ICON,onCurRootItemClick);
			_canTask.addEventListener(AutoPullUpListEvent.AUTO_CLICK_ICON,onCanRootItemClick);
			//点击当前根项的子项
			_currentTask.addEventListener(AutoPullUpListEvent.AUTO_CLICK_ITEM,onChildItemClick);
			_canTask.addEventListener(AutoPullUpListEvent.AUTO_CLICK_ITEM,onChildItemClick);
			
			//完成按鈕点击
			finishButton.addEventListener(MouseEvent.CLICK,onFinish);
			
			//放弃按钮点击
			giveUpButton.addEventListener(MouseEvent.CLICK,onGiveup);
			//任务超链接
			hyperlinkText.addEventListener(TextEvent.LINK,onTextLink);
			//任务描述链接
			//introduceText.addLinkClickHandel(onLinkClick);
			//tabbar点击
			tabBar.addEventListener(TabEvent.TAB_CLICK,onTab);
			
		}
		
		
		/**
		 * 树根点击 找到下一个有内容的 直接显示
		 * @param evt
		 */
		private function onCurRootItemClick(evt:AutoPullUpListEvent):void
		{
			if(_curRootItem!=evt.item)
			{
				_curRootItem	=	evt.item;
				_curRootItem.selectChildByIndex(0);
			}
		}
		
		private function onCanRootItemClick(evt:AutoPullUpListEvent):void
		{
			if(_canRootItem!=evt.item)
			{
				_canRootItem	=	evt.item;
				_canRootItem.selectChildByIndex(0);
			}
		}
		
		/**
		 * 清理任务详细信息 
		 */
		private function clearDetail():void
		{
			nameText.htmlStr 			=	"";
			introduceText.htmlStr 		=	"";
			hyperlinkText.htmlStr 		=	"";
			expInputLab.htmlStr 		=	"";
			silverInputLab.htmlStr		=	"";
			bindSilverInputLab.htmlStr	=	"";
			//清除奖励显示
			while(awardTextContainer.numChildren>0)
			{
				awardTextContainer.removeChildAt(0);
			}
			while(awardItemContainer.numChildren>0)
			{
				awardItemContainer.removeChildAt(0);
			}
		}
		
		/**
		 * 点击显示对应的任务
		 * 
		 */
		private function onChildItemClick(evt:AutoPullUpListEvent):void
		{
			_evt = evt;
			clearDetail();
			_infoScrollPanel.update();
			var tmpItem:AutoPullUpListItem	=	evt.item;
			if(tmpItem!=null &&tmpItem.data!=null)
			{
				//Tree 子项选择状态
				if(_currentTab==0)
				{
					if(tmpItem.openData.GetProperties("isOver") == 1)
					{
						giveUpButton.enabled = false;
						finishButton.enabled= false; 
					}
					else
					{
						giveUpButton.enabled = true;
						finishButton.enabled= true; 
					}
				}
				_currentTaskId	=	tmpItem.id;
				
				
				//任务名===========================================================
				nameText.htmlStr		=		StaticIni.getSwfLangStr("TaskName_" + _currentTaskId);
				
				//任务描述=========================================================
				introduceText.htmlStr	=		StaticIni.getSwfLangStr("TaskContext_" + _currentTaskId);
				
				//任务超链接=========================================================
				
				
				for(var j:int=0;j<_taskNumArray.length;j++)
				{
					if(_taskNumArray[j][0]==_currentTaskId)
					{
						killCount = _taskNumArray[j][1];
						_step		=	_taskNumArray[j][2];
					}
				}
				if(_currentTab==0)
				{
					hyperlinkText.htmlStr	=		StaticIni.getSwfLangStrVar("TaskStep_"+_currentTaskId + "_"+_step.toString(),[killCount]);
				}
				else
				{
					hyperlinkText.htmlStr	=		StaticIni.getSwfLangStrVar("TaskAccept_"+_currentTaskId,[killCount])
				}
				
				hyperlinkSp.y			=		introduceSp.y + introduceSp.height + 5;
				
				//任务奖励===========================================================
				formatAward(_currentTaskId,tmpItem.data);
			}
		}
		
		/**
		 * 根据任务ID，来显示任务奖励 
		 * @param pTaskId
		 * 
		 */
		private function formatAward(pTaskId:int,pArr:Array):void
		{
			awardSp.y = hyperlinkSp.y + hyperlinkSp.height + 5;
			//经验
			//================================================================
			var awardArr		:Array	=	[];
			var awardExp		:int	=	int(StaticIni.getIniVar(pTaskId,"AwardExp"));   //经验
			var awardMoney		:int	=	int(StaticIni.getIniVar(pTaskId,"AwardMoney")); //金钱
			var awardSpirit 	:int 	= 	int(StaticIni.getIniVar(pTaskId,"AwardSpirit"));//灵气
			var awardGold		:int	=	int(StaticIni.getIniVar(pTaskId,"AwardGold"));	// 仙玉
			
			var type	:int	=	int(StaticIni.getIniVar(pTaskId,"Type"));
			//如果是通缉榜的任务
			if(type==8)
			{
				/*var playerLevel	:int			=	Player.instance.data.GetProperties("Level");
				var color:int	=	int(StaticIni.getIniVar(pTaskId,"Color"));
				awardExp = TaskTools.wantedTaskExp(playerLevel,color);
				awardMoney	=	TaskTools.wantedTaseSilver(playerLevel,color);*/
			}
			awardArr.push([expLab,expInputLab,awardExp]);
			awardArr.push([silverLab,silverInputLab,awardMoney]);
			awardArr.push([bindSilverLab,bindSilverInputLab,awardSpirit]);
			awardArr.push([goldLab,goldInputLab,awardGold]);
			//组织显示 为0的不显示
			var idx:int	=	0;
			while(awardArr.length>0)
			{
				var dataItem	:Array	=	awardArr.shift();
				if(dataItem[2]==0)
				{
					continue;
				}
				else
				{
					var tmpVal:int	=	idx%2;
					dataItem[1].htmlStrByBorder	=	dataItem[2];
					awardTextContainer.addChild(dataItem[0]);
					awardTextContainer.addChild(dataItem[1]);
					dataItem[0].x	=	tmpVal==0?4:115;
					dataItem[1].x	=	tmpVal==0?40:150;
					if(idx>1)
					{
						dataItem[0].y	=	44;
						dataItem[1].y	=	44;
					}
					else
					{
						dataItem[0].y	=	25;
						dataItem[1].y	=	25;
					}
					idx++;
				}
			}
			
			//组织物品显示
			
			formatItem(pTaskId,pArr);
		}
		
		/**
		 * 显示奖励物品 
		 * @param pTaskId
		 * @param pArr
		 * 
		 */
		private function formatItem(pTaskId:int,pArr:Array):void
		{
			//组织物品显示
			//奖励
			var propList:Array = [];//总物品数组
			var itemStr:String = StaticIni.getIniVar(pTaskId,"AwardItem");
			if((itemStr!="")&&(itemStr!=null))//有任务奖励
			{
				propList =	itemStr.split(";");
				var baseY:Number = awardSp.height + 5;
				var dataArr	 : Array = [];
				var configID : int;//物品id 
				var num : int;		//物品数量
				var needSex : int;		//物品限制性别类型(0:无 1:男 2:女)
				var idx:int	=	0;
				var item:TaskAwardItem;
				while(propList.length>0)
				{
					dataArr	=	propList.shift().split(",");//0 物品ID ,1 物品数量
					needSex		=	int(StaticIni.getIniVar(dataArr[0],"NeedSex"));
					if(needSex == 0)
					{
						item = new (dataArr[0],dataArr[1]);
						item.x	=	idx%2==0?5:135;TaskAwardItem
						item.y	=	int(idx/2)*55 + baseY;
						awardItemContainer.addChild(item);
						_infoScrollPanel.update();
						idx++;
					}
					if(idx>=4)
					{
						break;	
					}
				}
			}
		}
		
		/**
		 * 立即完成按钮
		 */
		private function onFinish(evt:MouseEvent):void
		{
			if(_currentTaskId>0)
			{
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_DAILY_TASK_COMPLETE_ATONCE,_currentTaskId);
			}
		}
		
		/**
		 *放弃按钮的点击 
		 */
		private function onGiveup(evt:MouseEvent):void
		{
			if(_currentTaskId>0)
			{
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_TASK_GIVEUP,_currentTaskId);
			}
		}
		
		/**
		 *任务超链接 
		 * 追踪内容点击 
		 * @param evt
		 * <a href='event:1,12010101,2'> 
		 ：1代表 1皇城寻路 2野外寻路		3 代表打开世界地图
		 1后面ID是NPCID，2后面只要填场景号
		 */
		private function onTextLink(evt:TextEvent):void
		{
			var lnkArr	:Array	=	evt.text.split(",");
			var npcData	:Object	=	StaticIni.getIniObj(lnkArr[1]);
			dispatchEvent(new MouseEvent(MouseEvent.CLICK));
			if(lnkArr[0]=="3")
			{
				WorldMapUI.getInstance().show();
				return;
			}
		}
		
		/**
		 * tabar点击
		 **/
		private function onTab(evt:TabEvent):void
		{
			clearDetail();
			_currentTab	=	evt.item.id;
			if(_currentTab==0)
			{
				
				_currentTask.visible	=	true;
				_canTask.visible		=	false;
				_currentTask.selectFirstRoot();
				if(_curRootItem)
				{
					giveUpButton.visible 	=	true;
					finishButton.visible	=	true;	
					_curRootItem.selectChildByIndex(0);
				}
				else
				{
					giveUpButton.visible 	=	false;
					finishButton.visible	=	false;		
				}
				
			}
			else
			{
				giveUpButton.visible 	=	false;
				finishButton.visible	=	false;	
				_currentTask.visible	=	false;
				_canTask.visible		=	true;
				_canTask.selectFirstRoot();
				if(_canRootItem)
				{
					_canRootItem.selectChildByIndex(0);
				}
				
			}
		}
		
		
		/**
		 * 数据绑定 
		 */
		private function bindData():void
		{
			//已接任务
			bindManager.BindRecord(model.scene,RecordDefine.TASK_ACCEPTED, onAddRec, onRemoveRec);
			//可接任务
			bindManager.BindRecord(model.scene,RecordDefine.TASK_CAN_ACCEPT,onAddCanRec,onRemoveCanRec);
			//任务步骤的绑定
			bindManager.BindRecord(model.scene,RecordDefine.TASK_STEP,onAddRecStep,onRemoveRecStep);
		}
		
		/**
		 * 对任务步骤表进行显示
		 */
		private function onAddRecStep(key:String,pList:RecordObject):void
		{
			
			/*
			//任务步骤表
			Record_Declare_Begin( Task_Step );
			Column_Declare_Int( Id, 0 );				 //任务编号
			Column_Declare_Int( Step, 1 );				 //任务步骤
			Column_Declare_Int( Key, 2 );				 //关键字
			Column_Declare_Int( Cur, 3 );				 //当前完成度
			Column_Declare_Int( Total, 4 );				 //总进度
			Record_Declare_End
			*/
			if(pList != null)
			{
				_unbindArray.push([pList,bindManager.BindObjProp(pList,"3",onItemChange,[key])]);	//"3" 当前完成度
				
			}
		}
		/**
		 *当“3”列数据发生变化的时候 
		 * @param key
		 * @param val
		 * @param List
		 * 
		 */		
		private function onItemChange(key:String,val:int,List:Array):void
		{
			
			//取特定内容来更新
			var stepRecord	:Record	=	model.scene.GetRecordEx(RecordDefine.TASK_STEP);
			var line:String	=	List[0];
			var valR	:RecordObject	=	stepRecord.GetProperties(line);
			var TaskId		:int	=	valR.GetProperties("0");			//任务的id
			//var taskComplete:int	=	valR.GetProperties("4");	
			//			if(taskComplete==1)
			//			{
			//				text+= StaticIni.getSwfLangStr("TaskAnswerSuc_" + TaskId);
			//			}
			var num:int		=	valR.GetProperties("3");
			var step:int	=	valR.GetProperties("1");
			_taskNumArray.push([TaskId,num,step]);
			
		}
		
		
		
		/**
		 * 删除任务步骤
		 * @param key
		 * @param val
		 * 
		 */		
		private function onRemoveRecStep(key:String,val:RecordObject):void
		{
			if(val !=null)
			{
				
				var TaskId:int	=	val.GetProperties("0");
				var i:int;
				for each(var itemBind:Array in _unbindArray)
				{
					if((itemBind[0] as RecordObject).GetProperties("0")==val.GetProperties("0"))
					{
						bindManager.UnbindProp(itemBind.shift(),itemBind.shift(),itemBind.shift());
						_unbindArray.splice(i,1);
						for(var j:int=0;j<_taskNumArray.length;j++)
						{
							if(_taskNumArray[j]!=null)
							{
								if(_taskNumArray[j][0]==TaskId)
								{
									_taskNumArray.splice(j,1);
								}
							}
						
						}
						break;
					}
					i++;
				}
			}
		}
		
		
		
		/**
		 * 添加已接任务 
		 * @param key
		 * @param val
		 * 
		 */
		private function onAddRec(key:String,val:RecordObject):void
		{
			
			var taskId	:int	=	val.GetProperties("0");
			var type	:int	=	int(StaticIni.getIniVar(taskId,"Type"));
			var taskName	:String	=	StaticIni.getSwfLangStr("TaskName_"+taskId);
			var showType:int		=	val.GetProperties("9");
			var classId		:int	=	-1;
			if(showType>3)
			{
				classId = 2;
			}
			else
			{
				classId = showType-1;
			}
			var taskColor:String = taskName;
			//如果是通缉榜的任务要进行文字颜色的改变
			if(type==8)
			{
				var color:int	=	int(StaticIni.getIniVar(taskId,"Color"));
				taskColor = addColor(taskName,color);
			}
			_currentTask.addItem(taskColor,"","",classId,taskId,[val]);
			//绑定完成状态
			_bindAccArr.push([taskId,bindManager.BindRecordProp(val,"1",onTaskOver,[taskId])]);
			_currentTask.selectFirstRoot();
			_curRootItem.selectChildByIndex(0);
		}
		
		/**
		 *添加不同的颜色 
		 * @param str
		 * @return 
		 * 
		 */		
		private function addColor(str:String,color:int):String
		{
			var val:String	=	str;
			switch(color)
			{
				case WantedListUI.TASK_TRAIT_WHITE:
					val = StaticIni.getSwfLangStrVar("1000000033",[val]);
					break;
				case WantedListUI.TASK_TRAIT_GREEN:
					val = StaticIni.getSwfLangStrVar("1000000034",[val]);
					break;
				case WantedListUI.TASK_TRAIT_BLUE:
					val = StaticIni.getSwfLangStrVar("1000000035",[val]);
					break;
				case WantedListUI.TASK_TRAIT_PURPLE:
					val = StaticIni.getSwfLangStrVar("1000000036",[val]);
					break;
				case WantedListUI.TASK_TRAIT_ORANGE:
					val = StaticIni.getSwfLangStrVar("1000000038",[val]);
					break;
				case WantedListUI.TASK_TRAIT_GOLDEN:
					val = StaticIni.getSwfLangStrVar("1000000039",[val]);
					break;
				default:
					break;
			}
			
			return val;
		}
			
		
		
		/**
		 *重新选中第一个任务 
		 * 
		 */		
		private function refresh():void
		{
			
		}
		
		/**
		 * 任务状态绑定 
		 * @param key
		 * @param val
		 * @param pList
		 * 
		 */		
		private function onTaskOver(key:String,val:int,pList:Array):void
		{
			var taskItem	:AutoPullUpListItem	= _currentTask.getItemById(pList[0]) as AutoPullUpListItem;
			if(taskItem)
			{
				if(val == 1)//任务完成
				{
					taskItem.modifyChildBg("bgFrame_12");
					taskItem.modifyChildIcon("Task_Completed.png");
				}
				taskItem.openData.HandleProperties("isOver",val);
			}
		}
		
		/**
		 * 移除已接任务 
		 * @param key
		 * @param val
		 * 
		 */
		private function onRemoveRec(key:String,val:RecordObject):void
		{
			var taskId	:int	=	val.GetProperties("0");
			var taskItem	:AutoPullUpListItem	=	_currentTask.getItemById(taskId);
			_currentTask.removeItemById(taskId);
			//解绑完成状态
			var tmpArr	:Array	=	[];
			for(var i:int=0;i<_bindAccArr.length;i++)
			{
				tmpArr	=	_bindAccArr[i];
				if(tmpArr[0]==taskId)
				{
					bindManager.UnbindProp(val,"1",tmpArr[1]);
					_bindAccArr.splice(i,1);
				}
			}
			_currentTask.selectFirstRoot();
			_curRootItem.selectChildByIndex(0);
		}
		
		
		/**
		 * 添加可接任务 
		 * @param key
		 * @param val
		 * 
		 */
		private function onAddCanRec(key:String,val:RecordObject):void
		{
			var taskId	:int	=	val.GetProperties("0");
			var type	:int	=	int(StaticIni.getIniVar(taskId,"Type"));
			if(type==8)
			{
				return;
			}
			var classId		:int	=	-1;
			var showType:int	=	val.GetProperties("1");
			var taskName	:String	=	StaticIni.getSwfLangStr("TaskName_"+taskId);
			if(showType>3)
			{
				classId = 2;
			}
			else
			{
				classId = showType-1;
			}
			_canTask.addItem(taskName,"","",classId,taskId,[val]);
		}
		
		/**
		 *	创建超链接 
		 * @param str
		 * @return 
		 */		
		private function createLink(taskId:int):String
		{
			var link:String;
			link	="<a href=\"event:"+taskId;
			link	+="\"><u>";
			link	+= StaticIni.getSwfLangStr("TaskStep_"+taskId);
			link	+="</u></a>";
			return link;
		}
		
		/**
		 * 根据选项条与任务ID来选择 
		 * @param pTabId
		 * @param pTaskId
		 * 
		 */
		public function selectItemByTabAndId(pTabId:int,pTaskId:int):void
		{
			tabBar.selectTabByIndex(pTabId);
			if(pTabId==0)
			{
				_currentTask.selectItemById(pTaskId);
			}
			else
			{
				_canTask.selectItemById(pTaskId);
			}
			super.show();
		}
		
		/**
		 * 移除可接任务 
		 * @param key
		 * @param val
		 * 
		 */
		private function onRemoveCanRec(key:String,val:RecordObject):void
		{
			var taskId	:int	=	val.GetProperties("0");
			var type	:int	=	int(StaticIni.getIniVar(taskId,"Type"));
			if(type==8)
			{
				return;
			}
			_canTask.removeItemById(taskId);
		}
		
		/**
		 * 重写显示 用来显示选中 
		 * @param space
		 * @param onshow
		 * @param argc
		 * 
		 */
		override public function show(space:String=MIDDLELAYER, onshow:Function=null):void
		{
			tabBar.selectTabByIndex(0);
			_currentTask.selectFirstRoot();
			if(null!=_curRootItem)
			{
				_curRootItem.selectChildByIndex(0);
			}
		
			super.show(space,onshow);	
		}
		
	}
}